package com.im.app.controller;


import com.im.app.model.Lixian;
import com.im.app.service.LixianService;
import com.im.app.utils.Response;
import com.im.app.utils.ResponseResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/lixian")
public class LixianController {

    @Resource
    private LixianService lixianService;

    @RequestMapping(value = "/queryLixianList",method= RequestMethod.POST)
    public ResponseResult<List<Lixian>> queryLixianList() {
        try {
            //调用业务层返回列表
            List<Lixian> lixianList = lixianService.queryLixianList();
            return Response.makeOKRsp(lixianList);
        } catch (Exception e) {
            e.printStackTrace();
            return Response.makeErrRsp("查询离线语信息异常");
        }
    }

    @RequestMapping(value ="/find/{id}",method=RequestMethod.POST)
    public ResponseResult<Lixian> findLixian(@PathVariable("id") Integer id) {
        try {
            //调用业务层返回列表
            Lixian lixian = lixianService.findLixian(id);
            return Response.makeOKRsp(lixian);
        } catch (Exception e) {
            e.printStackTrace();
            return Response.makeErrRsp("查询离线语信息异常");
        }
    }

    @RequestMapping(value ="/delete/{id}",method=RequestMethod.POST)
    public ResponseResult deleteLixian(@PathVariable("id") Integer id) {
        int result = lixianService.deleteLixian(id);
        if(result>0){
            return Response.makeOKRsp("删除成功");
        }else{
            return Response.makeErrRsp("删除失败");
        }

    }

    @RequestMapping(value ="/add",method=RequestMethod.POST)
    public ResponseResult addLixian(Lixian Lixian) {
        int result = lixianService.addLixian(Lixian);
        if(result>0){
            return Response.makeOKRsp("添加成功");
        }else{
            return Response.makeErrRsp("添加失败");
        }
    }

    @RequestMapping(value ="/update",method=RequestMethod.POST)
    public ResponseResult updateLixian(Lixian Lixian) {

        int result = lixianService.updateLixian(Lixian);
        if(result>0){
            return Response.makeOKRsp("修改成功");
        }else{
            return Response.makeErrRsp("修改失败");
        }

    }








}
